package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.DamageListGoodsVo;
import com.atguigu.jxc.entity.Log;
import com.atguigu.jxc.service.DamageService;
import com.atguigu.jxc.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;
import java.util.List;
import java.util.Map;

/**
 *
 * 报损单
 * @author dyqstart
 * @create 2021-09-04-14:53
 * @since 1.0.0
 */
@RestController
@RequestMapping("/damageListGoods")
public class DamageController {

    @Autowired
    DamageService damageService;

    @Autowired
    LogService logService;

    /**
     * 保存报损单
     * @param //damageNumber
     * @param damageList
     * @param damageListGoodsStr
     * @return
     */
    @PostMapping("/save")
    public ServiceVO saveDamage(DamageList damageList,
                                String damageListGoodsStr){

        damageService.saveDamage(damageList,damageListGoodsStr);
        Log log = new Log(Log.INSERT_ACTION,"新增报损单");
        logService.save(log);
        return new ServiceVO(100,"请求成功",null);
    }

    @PostMapping("/list")
    public Map<String,Object> getDamageList(String sTime,String eTime){

        Map<String,Object> map = damageService.getDamageList(sTime,eTime);
        Log log = new Log(Log.SELECT_ACTION,"查询报损单列表");
        logService.save(log);
        return map;
    }

    @PostMapping("/goodsList")
    public Map<String,Object> getDamageListGoods(Integer damageListId){

        Map<String,Object> map = damageService.getDamageListGoods(damageListId);
        Log log = new Log(Log.SELECT_ACTION,"查询报损单分页列表");
        logService.save(log);
        return map;
    }
}
